package com.homegoods.home;

import android.util.Log;

import com.homegoods.area.model.SubModelList;
import com.homegoods.classify.model.Constant;
import com.homegoods.home.model.AdvertisingModel;
import com.homegoods.home.model.HomeClassModel;
import com.network.retrofit_rx.Api.ActionSubscriber;
import com.network.retrofit_rx.Api.CommandImpl;
import com.network.retrofit_rx.Api.HttpManager;


import java.util.List;

import io.reactivex.functions.Consumer;

public class HomeApiUtils {

    /**
     * 获取首页新品列表
     *
     * @param
     * @param
     * @param consumer AppType=commodity_&&SpecialAD=comclass_303394a739434a9897d8b320c2ac8902&SpecialADWay=like&psize=50&pos=1
     */
    public static void HomeComdiyList(String childSid, int page, int pos, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.DLIST_CENTER)
                .addParams("AppType", "commodity_")
                .addParams("SpecialAD", "comclass_303394a739434a9897d8b320c2ac8902")
                .addParams("SpecialADWay", "like")
                .addParams("SClassTree", childSid)
                .addParams("SClassTreeWay", "like")
                .addParams("psize", page)
                .addParams("pos", pos)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取首页商品大分列表
     *
     * http://full-link.cn/amapi/SimplePlanCmd.aspx?cmd=MainMenuCmd
     * @param
     * @param
     * @param consumer
     */
    public static void getHomeClass(Consumer<List<HomeClassModel>> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.SIMPLE_PLAN_CMD)
                .addParams("cmd", "MainMenuCmd")
                .addParams("outdata", "jsonlist")
                .setObject(false)
                .setClass(HomeClassModel.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取首页大广告列表
     *
     * @param
     * @param
     * @param consumer
     */
    public static void getAdvertising(Consumer<AdvertisingModel> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.DLIST_CENTER)
                .addParams("AppType", "Advertising_")
                .addParams("outdata", "json")
                .setObject(true)
                .setClass(AdvertisingModel.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取商品列表
     *
     * @param
     * @param
     * @param consumer 【例】/AMAPI/DListCenter.aspx?AppType=commodity_&SClassTree=comclass_14f7fd2d76d24608abfc913332dcb09e&SClassTreeWay=like&psize=50&pos=1
     */
    public static void ComdiyList(String sid, int pagaSize, int pos, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.DLIST_CENTER)
                .addParams("AppType", "commodity_")
                .addParams("SClassTree", sid)
                .addParams("SClassTreeWay", "like")

                .addParams("psize", pagaSize)
                .addParams("pos", pos)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 按供应商家找商品：
     *
     * @param
     * @param
     * @param consumer AppType=commodity_&&Businessman=factory_4c1422f0511842189f83bcc26d0d73a5&SClassTreeWay=equal&psize=50&pos=1
     */
    public static void getClassTreeCommodity(String sid,int pos, String type, String value, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.DLIST_CENTER)
                .addParams("AppType", "commodity_")
                .addParams("Businessman", sid)
                .addParams("SClassTreeWay", "equal")
                .addParams("pos", pos)
                .addParams(type, value)
                .addParams("psize", 20)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 终端全局配置
     *
     * @param
     * @param
     * @param consumer AppType=commodity_&&Businessman=factory_4c1422f0511842189f83bcc26d0d73a5&SClassTreeWay=equal&psize=50&pos=1
     */
    public static void startAppGetDeviceConfig(Consumer<String> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.JSONDATA_VERSION)
                .setObject(true)
                .setClass(String.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

}
